package com.zzedu.web.controller.system;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.system.domain.SysNotice;
import com.zzedu.system.service.ISysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 公告 信息操作处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController {
    @Autowired
    private ISysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    @PreAuthorize("@permission.hasAnyPermissions('system:notice:list')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody SysNotice notice) {
        IPage<SysNotice> list = noticeService.selectNoticeList(notice.getPageDTO(), notice);
        return getDataTable(list);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @PreAuthorize("@permission.hasAnyPermissions('system:notice:query')")
    @RequestMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable Long noticeId) {
        return success(noticeService.getById(noticeId));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@permission.hasAnyPermissions('system:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult add(@Validated @RequestBody SysNotice notice) {
        return toAjax(noticeService.save(notice));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@permission.hasAnyPermissions('system:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @RequestMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody SysNotice notice) {
        return toAjax(noticeService.updateById(notice));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@permission.hasAnyPermissions('system:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @RequestMapping("/remove/{noticeIds}")
    public AjaxResult remove(@PathVariable List<Long> noticeIds) {
        return toAjax(noticeService.removeBatchByIds(noticeIds));
    }
}
